/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author selam
 */
@Entity
@Table(name = "product")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findByProductId", query = "SELECT p FROM Product p WHERE p.productId = :productId"),
    @NamedQuery(name = "Product.findByAmountAvailaible", query = "SELECT p FROM Product p WHERE p.amountAvailaible = :amountAvailaible")})
public class Product implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ProductId")
    private Integer productId;
    @Column(name = "AmountAvailaible")
    private Integer amountAvailaible;
    @JoinColumn(name = "User_Id", referencedColumnName = "User_Id")
    @ManyToOne(optional = false)
    private User userId;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "product")
    private Flight flight;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productId")
    private Collection<Modificaton> modificatonCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "product")
    private Hotel hotel;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "product")
    private Excursion excursion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "productId")
    private Collection<Productcontainment> productcontainmentCollection;

    public Product() {
    }

    public Product(Integer productId) {
        this.productId = productId;
    }

    public Integer getProductId() {
        return productId;
    }

    public void setProductId(Integer productId) {
        this.productId = productId;
    }

    public Integer getAmountAvailaible() {
        return amountAvailaible;
    }

    public void setAmountAvailaible(Integer amountAvailaible) {
        this.amountAvailaible = amountAvailaible;
    }

    public User getUserId() {
        return userId;
    }

    public void setUserId(User userId) {
        this.userId = userId;
    }

    public Flight getFlight() {
        return flight;
    }

    public void setFlight(Flight flight) {
        this.flight = flight;
    }

    @XmlTransient
    public Collection<Modificaton> getModificatonCollection() {
        return modificatonCollection;
    }

    public void setModificatonCollection(Collection<Modificaton> modificatonCollection) {
        this.modificatonCollection = modificatonCollection;
    }

    public Hotel getHotel() {
        return hotel;
    }

    public void setHotel(Hotel hotel) {
        this.hotel = hotel;
    }

    public Excursion getExcursion() {
        return excursion;
    }

    public void setExcursion(Excursion excursion) {
        this.excursion = excursion;
    }

    @XmlTransient
    public Collection<Productcontainment> getProductcontainmentCollection() {
        return productcontainmentCollection;
    }

    public void setProductcontainmentCollection(Collection<Productcontainment> productcontainmentCollection) {
        this.productcontainmentCollection = productcontainmentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productId != null ? productId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.productId == null && other.productId != null) || (this.productId != null && !this.productId.equals(other.productId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Product[ productId=" + productId + " ]";
    }
    
}
